﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WikiQuizz.Common.Interfaces;
using System.Xml.Linq;
using WikiQuizz.Common.Resource;

namespace WikiQuizz.StandardImplementations
{
    public class CapitalFilter: ICapitalFilter
    {
        public string Filter(IEnumerable<XNode> rawData)
        {
            var values = (from XElement o in rawData
                           select o.Value);

            var withoutDeJure = (from o in values
                                 where !o.ToUpper().Contains("DE JURE")
                                 select o);

            var withoutDeFacto = (from o in withoutDeJure
                                  where !o.ToUpper().Contains("DE FACTO")
                                  select o);

            var withoutAngleBrackets = (from o in withoutDeFacto
                                        where !o.StartsWith("[")
                                        select o);

            var withoutCapitalTag = (from o in withoutAngleBrackets
                                     where !o.Contains(Strings.CAPITAL_IDENTIFYER)
                                     select o);

            var res = withoutCapitalTag.FirstOrDefault();

            return res;
        }
    }
}
